package com.naizhuai.ui.user.multtype;

import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.naizhuai.Model.AccountHelper;
import com.naizhuai.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.drakeet.multitype.ItemViewBinder;

/**
 * @author：lichenxi
 * @date 2018/5/28 16
 * email：525603977@qq.com
 * Fighting
 */
public class PersonInfoViewBinder extends ItemViewBinder<PersonInfo, PersonInfoViewBinder.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_person_info, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull PersonInfo personInfo) {
        holder.imageRes.setImageResource(personInfo.resid);
        holder.titleName.setText(personInfo.infoName);
        holder.titleDetail.setText(personInfo.infoDetial);
        holder.titleDetail.setSelected(true);
        if (personInfo.isarrow) {
            holder.arrowRight.setVisibility(View.VISIBLE);
        } else {
            holder.arrowRight.setVisibility(View.INVISIBLE);
        }

        holder.itemView.setOnClickListener(v -> holder.itemView.post(() -> personInfo.run()));

       if (personInfo.isQrCode){
           Drawable drawable= ContextCompat.getDrawable(holder.itemView.getContext(),R.drawable.qricon);
           drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
           holder.titleDetail.setCompoundDrawables(null, null, drawable, null);
           holder.titleDetail.setCompoundDrawablePadding(20);
        }else {
           holder.titleDetail.setCompoundDrawables(null,null,null,null);
        }

    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.image_res)
        ImageView imageRes;
        @BindView(R.id.title_name)
        TextView titleName;
        @BindView(R.id.title_detail)
        TextView titleDetail;
        @BindView(R.id.arrow_right)
        ImageView arrowRight;
        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
